import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hktk_app/dao/order_dao.dart';
import 'package:hktk_app/dialog/buy_dialog.dart';

class OrderDetailPage extends StatefulWidget {
  final String orderId;
  final String packageName;

  OrderDetailPage({Key? key, required this.orderId, required this.packageName})
      : super(key: key);

  @override
  State<StatefulWidget> createState() => _createOrderDetailPageState();
}

class _createOrderDetailPageState extends State<OrderDetailPage> {
  late Future<dynamic> detail;

  @override
  Widget build(BuildContext context) {
    // 
    return Scaffold(
      appBar: AppBar(
        title: Text("订单详情"),
      ),
      body: Container(
        child: FutureBuilder(
          future: detail,
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.done) {
              // snapshot.data
              var data = snapshot.data! as Map<String, dynamic>;
              var paymentModel = data["paymentModel"] as Map<String, dynamic>?;
              var assets = (data["oneDetail"] as Map<String, dynamic>)["assets"]
                  as Map<String, dynamic>;
              return Container(
                  padding: EdgeInsets.all(10),
                  child: Column(
                    children: [
                      Container(
                        child: Text(
                          widget.packageName,
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.bold),
                        ),
                      ),
                      Container(
                          child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                            Text("考试："),
                            Text(assets["examName"] as String),
                          ])),
                      if (paymentModel != null)
                        Container(
                            child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                              Text("支付类型："),
                              Text(((paymentModel["mode"] as String) == "pc"
                                      ? "电脑"
                                      : "手机") +
                                  ((paymentModel["paymentType"] as String) ==
                                          "alipay"
                                      ? "支付宝"
                                      : (paymentModel["paymentType"]
                                                  as String) ==
                                              "weixin"
                                          ? "微信支付"
                                          : "其他支付")),
                            ])),
                      Container(
                          child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                            Text("创建时间："),
                            Text((data["createdTime"] as String)),
                          ])),
                      Container(
                          child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                            Text("有效时间："),
                            Text("30分钟"),
                          ])),
                      if (paymentModel != null)
                        Container(
                            child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                              Text("支付状态："),
                              Text((paymentModel["paymentStatus"] as String) ==
                                      "waitPay"
                                  ? "等待支付"
                                  : "支付成功"),
                            ])),

                      Container(
                          child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                            Text("支付金额："),
                            Text("￥${data["priceDecimal"] as double}",
                                style: TextStyle(color: Colors.red)),
                          ])),

                      // 未过期，未支付
                      // if(!(data["havePay"] as bool)&& DateTime.parse(data["expiredDate"] as String).toUtc().compareTo(DateTime.now().toUtc())>0)
                      //   Container(
                      //       alignment: Alignment.centerRight,
                      //       child: TextButton(onPressed: (){
                      //       //   弹出支付弹框
                      //         var height = ScreenUtil().screenHeight;
                      //         double sheetHeight = height * 0.8;
                      //         // 弹出层
                      //         showModalBottomSheet(
                      //           context: context,
                      //           // 设置底部弹出框全屏显示
                      //           isScrollControlled: true,
                      //           // 自定义弹出层高度
                      //           constraints: BoxConstraints(maxHeight: sheetHeight),
                      //           // 自定义圆角
                      //           shape: RoundedRectangleBorder(
                      //             borderRadius: BorderRadius.only(
                      //               topLeft: Radius.circular(24),
                      //               topRight: Radius.circular(24),
                      //             ),
                      //           ),
                      //           builder: (BuildContext context) {
                      //             //获取套餐
                      //             return FutureBuilder(future: () async{
                      //
                      //             }(), builder: (BuildContext context1, AsyncSnapshot snapshot){
                      //
                      //               return Container();
                      //             });
                      //             // return BuyDialog(
                      //             //   package: list[index],
                      //             //   index: 1,
                      //             //   payHide: false,
                      //             // );
                      //           },
                      //         );
                      //       }, child: Text("支付",style: TextStyle(color: Colors.blue),))),
                    ],
                  ));
            }
            return CircularProgressIndicator();
          },
        ),
      ),
    );
  }

  @override
  void initState() {
    //   initState
    super.initState();
    detail = OrderDao.getOrderDetail(widget.orderId);
  }
}
